package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class ZhuoerClient {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			Socket s = new Socket("localhost", 6666);
			System.out.println("ip:" + s.getInetAddress() + "，本地端口："
					+ s.getLocalPort() + "，远程端口：" + s.getPort());

			InputStream in = s.getInputStream();
			OutputStream out = s.getOutputStream();

			PrintWriter pw = new PrintWriter(out);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			while (true) {

				System.out.println("input your words:");
				String word = sc.nextLine();

				pw.println(word);
				pw.flush();
				if (word.equals("quit"))
					break;

				String echo = br.readLine();
				System.out.println("服务器说：" + echo);
			}
			s.close();
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}

	}

}
